import { IFeidaoAiNodejsComponent } from '../../interfaces';

/**
 * 生成带参数的url地址
 * @param fd 固定参数
 * @param [query] 参数
 * @returns url地址
 * @example direct(fd,query);
 */
export default function direct(fd: IFeidaoAiNodejsComponent, query?: any) {
	let url = fd.data.url;
	if (query) {
		// url = generate(query, url);
		const usp = new URLSearchParams();
		for (const k in query) {
			if (query.hasOwnProperty(k)) {
				usp.append(k, query[k]);
			}
		}
		const url_param = usp.toString();
		url = url.split('?')[0] + (url_param && url_param.length !== 0 ? '?' + url_param : '');
	}
	return url;
}
